import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {VideoService} from '../video.service';
import {Video} from '../video';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-videolist',
    templateUrl: './videolist.component.html',
})
export class VideolistComponent implements OnInit {

    data: Video[] = [];
    total = 0;
    pagesize = 10;
    pageCureent = 1;

    constructor(
        private vedioservice: VideoService,
        private msg: NzMessageService
    ) {
    }

    ngOnInit() {
        this.getlist(this.pageCureent);
    }


    getlist($event) {
        this.vedioservice.getVedioList($event - 1).subscribe(res => {
            this.data = res['list'];
            this.total = res['totalElement'];
            this.pagesize = res['pageSize'];
            this.pageCureent = $event;
        }, __ => {
        });
    }

    dellight(item) {
        const index = this.data.indexOf(item);
        this.data = [...this.data.slice(0, index), ...this.data.slice(index + 1, this.data.length)];
        this.vedioservice.dellight(item['id']).subscribe(res => {
            this.msg.success('删除成功');
        }, __ => {
            this.vedioservice.getVedioList(this.pageCureent);
        });
    }
}
